/**
 * 移动端主题默认配置
 */
import type { DressResourceApi } from '#/api/wedding/dressresource';

// 默认主题配置
export const DEFAULT_THEME_CONFIG: DressResourceApi.MobileThemeConfig = {
  type: 'modern',
  primaryColor: '#ff1493',
  secondaryColor: '#ff69b4',
  headerStyle: 'elegant',
  cardStyle: 'shadow',
};

// 预设主题列表
export const PRESET_THEMES = [
  {
    type: 'chinese',
    label: '中式风格',
    description: '中国传统婚礼风格，红色为主',
    icon: 'lucide:chinese-yuan',
    config: {
      type: 'chinese' as const,
      primaryColor: '#dc143c',
      secondaryColor: '#ffd700',
      headerStyle: 'classic' as const,
      cardStyle: 'border' as const,
    },
  },
  {
    type: 'european',
    label: '欧式风格',
    description: '欧洲宫廷风格，典雅华贵',
    icon: 'lucide:castle',
    config: {
      type: 'european' as const,
      primaryColor: '#800080',
      secondaryColor: '#ffd700',
      headerStyle: 'elegant' as const,
      cardStyle: 'gradient' as const,
    },
  },
  {
    type: 'modern',
    label: '现代简约',
    description: '现代简约风格，清新时尚',
    icon: 'lucide:sparkles',
    config: {
      type: 'modern' as const,
      primaryColor: '#ff1493',
      secondaryColor: '#ff69b4',
      headerStyle: 'simple' as const,
      cardStyle: 'shadow' as const,
    },
  },
  {
    type: 'vintage',
    label: '复古风格',
    description: '复古怀旧风格，优雅浪漫',
    icon: 'lucide:flower-2',
    config: {
      type: 'vintage' as const,
      primaryColor: '#8b4513',
      secondaryColor: '#daa520',
      headerStyle: 'classic' as const,
      cardStyle: 'border' as const,
    },
  },
  {
    type: 'bohemian',
    label: '波西米亚',
    description: '自由奔放风格，自然清新',
    icon: 'lucide:leaf',
    config: {
      type: 'bohemian' as const,
      primaryColor: '#228b22',
      secondaryColor: '#98fb98',
      headerStyle: 'simple' as const,
      cardStyle: 'shadow' as const,
    },
  },
];

// 获取全局默认主题（从 localStorage）
export function getGlobalThemeConfig(): DressResourceApi.MobileThemeConfig {
  try {
    const stored = localStorage.getItem('wedding_global_theme_config');
    if (stored) {
      return JSON.parse(stored);
    }
  } catch (error) {
    console.error('获取全局主题配置失败:', error);
  }
  return DEFAULT_THEME_CONFIG;
}

// 设置全局默认主题
export function setGlobalThemeConfig(config: DressResourceApi.MobileThemeConfig): void {
  try {
    localStorage.setItem('wedding_global_theme_config', JSON.stringify(config));
  } catch (error) {
    console.error('设置全局主题配置失败:', error);
  }
}

// 合并主题配置（优先级：婚纱配置 > 全局配置 > 系统默认）
export function mergeThemeConfig(
  dressConfig?: DressResourceApi.MobileThemeConfig,
): DressResourceApi.MobileThemeConfig {
  const globalConfig = getGlobalThemeConfig();
  
  return {
    ...DEFAULT_THEME_CONFIG,
    ...globalConfig,
    ...dressConfig,
  };
}

